// 自定义国际化配置
import { createI18n } from 'vue-i18n'
import defaultSettings from '@/settings'
// 本地语言包
import zhCNLocale from './zh_CN'
import enUSLocale from './en_US'
import ruRULocale from './ru_RU'

import zhCnElement from 'element-plus/es/locale/lang/zh-cn'
import enElement from 'element-plus/es/locale/lang/en'
import ruElement from 'element-plus/es/locale/lang/ru'

const messages = {
  zh_CN: {
    ...zhCNLocale,
  },
  en_US: {
    ...enUSLocale,
  },
  ru_RU: {
    ...ruRULocale,
  },
}

/**
 * 获取当前语言
 * @returns zh-cn|en ...
 */
export const getLanguage = () => {
  const language = useStorage('language', defaultSettings.language)
  if (language.value) {
    return language.value
  }
}

export const getElementLanguage = () => {
  const elementMessages = {
    zh_CN: zhCnElement,
    en_US: enElement,
    ru_RU: ruElement,
  }
  const language = useStorage('language', defaultSettings.language)
  return elementMessages[language.value]
}

const i18n = createI18n({
  legacy: false,
  locale: getLanguage(),
  messages,
})

export default i18n
